/**
 * 数据对象基类
 */
// import { httpRequest } from './util/httpRequest.js'    //引入类
// import { apiCode} from "./util/apiCode";
// import { config} from "./util/config.js";

const httpRequest=require("./util/httpRequest.js")
const apiCode=require("./util/apiCode.js")
const config=require("./util/config.js")
class DGObject {
  //构造函数
  constructor(options,type,domain) {
    this.ID = options.ID;
    this.name = options.name;
    this.type = type;
    this.domain = domain;
  }
  //查询条件
  queryData(condition){
    let baseUrl = config.getApiServerUrl();
    let domain = this.domain;
    let type = this.type;
    let prj = config.getPrjCode();
    let filter = apiCode.EnCode(condition);
    let string =`${baseUrl}/api/${domain}/${type}?project=${prj}&filter=${filter}`;
    return  new Promise(function (resolve, reject) {
      httpRequest.sendRrquest(`${baseUrl}/api/${domain}/${type}?project=${prj}&filter=${filter}`, "GET", {})
        .then(function (res) {
          resolve(res.data);
        }, function (error) {
          reject(error);
        })
    });
  }
  //获取地质信息，包括DGSR、地质预报、不良地质信息
  queryGeology(mili){
    let baseUrl = config.getGeologyServiceUrl();
    let domain = this.domain;
    let type = this.type.toLowerCase();
    let prj = config.getGeologyPrjCode();
    var url=`${baseUrl}/api/${domain}/${type}?project=${prj}&MileageStr=${mili}`;
    return  new Promise(function (resolve, reject) {
      httpRequest.sendRrquest(url, "GET", {})
        .then(function (res) {
          resolve(res.data);
        }, function (error) {
          reject(error);
        })
    });
  }
  queryDataTop(condition,topNum){
    let baseUrl = config.getApiServerUrl();
    let domain = this.domain;
    let type = this.type;
    let prj = config.getPrjCode();
    let filter = apiCode.EnCode(condition);
    return new Promise(function (resolve, reject) {
      httpRequest.sendRrquest(`${baseUrl}/api/${domain}/${type}?project=${prj}&filter=${filter}&topNum=${topNum}`, "GET", {})
        .then(function (res) {
          resolve(res.data);
        }, function (error) {
          reject(error);
        })
    });
  }
  addData(){
    let baseUrl = config.getApiServerUrl();
    let domain = this.domain;
    let type = this.type;
    let prj = config.getPrjCode();
    let that =this;
    return new Promise(function (resolve, reject) {
      httpRequest.sendRrquest(`${baseUrl}/api/${domain}/${type}?project=${prj}`, "PUT", that)
        .then(function (res) {
          resolve(res.data);
        }, function (error) {
          reject(error);
        })
    });
  }
  queryDataTest(condition, topNum) {
    let baseUrl = config.getApiServerUrl();
    let domain = this.domain;
    let type = this.type;
    let prj = config.testPrjCode();
    let filter = apiCode.EnCode(condition);
    return new Promise(function (resolve, reject) {
      httpRequest.sendRrquest(`${baseUrl}/api/${domain}/${type}?project=${prj}&filter=${filter}&topNum=${topNum}`, "GET", {})
        .then(function (res) {
          resolve(res.data);
        }, function (error) {
          reject(error);
        })
    });

  }
  deleteData(){

  }

}
module.exports = DGObject
// export { DGObject }